package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.Area;
import com.realtyManage.springboot.Model.Do.Discuss;
import com.realtyManage.springboot.Model.Do.HouseDynamic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 你问我答
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-10-29
 */

@Repository
public interface DiscussRepository extends JpaRepository<Discuss, Integer>, JpaSpecificationExecutor<Discuss> {

    @Transactional
    @Modifying
    @Query(value="delete from discuss where id = ?1 OR parent_id = ?1",nativeQuery=true)
    int deleteDiscuss(Integer id);


    @Query(value="select * from discuss where type = 1 ORDER BY time DESC",nativeQuery=true)
    List<Discuss> getDiscussTree();

    @Query(value="select * from discuss where type = 0 AND parent_id = 0 ORDER BY time DESC",nativeQuery=true)
    List<Discuss> getAuditDiscuss();

    @Transactional
    @Modifying
    @Query(value="update discuss set type = 1 where id = ?1",nativeQuery=true)
    int updateDiscuss(Integer id);


    @Query(value="select * from discuss where id = ?1 OR parent_id = ?1 ORDER BY time DESC",nativeQuery=true)
    List<Discuss> getDiscussTreeDetailById(String id);
}
